<?php

class My_Controller_Plugin_Multilanguage extends Zend_Controller_Plugin_Abstract {

    public function routeStartup(Zend_Controller_Request_Abstract $request) {
        $tmp = str_replace($request->getBaseUrl(), "", $request->getRequestUri());

        $tmp2 = trim($tmp,"/");
        $tmp2 = preg_split('[/]', $tmp2);
        
        if (strlen($tmp2[0]) != 2) {
            $default_language = Zend_Registry::get("default_language");
            $request->setRequestUri($request->getBaseUrl() . "/$default_language" . $tmp);
            $request->setParam("language", "$default_language");
        }
    }

    public function routeShutdown(Zend_Controller_Request_Abstract $request) {
        $language = $request->getParam("language");

        $locale = new Zend_Locale($language);

        $translate = Zend_Registry::get('Zend_Translate');
        $translate->setLocale($locale);
    }

}

?>